home *** CD-ROM | disk | FTP | other *** search
/ IRIX 6.4 Applications 1997 August / SGI IRIX 6.4 Applications 1997 August.iso / dist / gateway.idb / usr / WebFace / Tasks / connect-second.cgi.z / connect-second.cgi
Encoding:
Text File  |  1997-07-30  |  8.0 KB  |  253 lines

  1. #!/usr/bin/perl5
  2. #
  3. # connect-second.cgi
  4. #
  5. # Copyright 1988-1996 Silicon Graphics, Inc.
  6. # All rights reserved.
  7. #
  8. # This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  9. # the contents of this file may not be disclosed to third parties, copied or
  10. # duplicated in any form, in whole or in part, without the prior written
  11. # permission of Silicon Graphics, Inc.
  12. #
  13. # RESTRICTED RIGHTS LEGEND:
  14. # Use, duplication or disclosure by the Government is subject to restrictions
  15. # as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  16. # and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  17. # successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  18. # rights reserved under the Copyright Laws of the United States.
  19. #
  20. # $Id: connect-second.cgi,v 1.27 1997/06/19 22:26:46 shotes Exp $
  21.  
  22. require "/usr/OnRamp/lib/OnRamp.pm";
  23.  
  24. if (!$ARGV[0]) { printf("Location: %s%c%c","/tasks/Tasks.connect-start.cgi",10,10); }
  25.  
  26.  
  27. $myname = "connect-second.cgi";
  28. $temp = "task.tmp";
  29. $data = "task.dummy";
  30. $htnet = "/usr/OnRamp/bin/htnetwork";
  31. $action= "connect-second.cgi?loop";
  32.  
  33. $it = "<td align=right>";
  34. $ni = "</td>";
  35. $bo = "<td><font size=5><i>";
  36. $nb = "</i></font></td>";
  37.  
  38. @find_vals = ('hardware','mailserver');
  39.  
  40. &get_fields;
  41.  
  42. if ($ARGV[0] eq 'loop') { %vals = %fld;  }
  43. else { &readValues; }
  44.  
  45. $t1board = &isT1Board;
  46. $eboard = &isSecondEboard;
  47.  
  48. if ($ARGV[0] eq loop) {
  49.    &errorCheck;
  50.    &writeFile;
  51.  
  52.     if ($fld{'hardware'} eq 'Modem') { $go = "/tasks/connect-modem.cgi?s"; }
  53.     elsif ($fld{'hardware'} eq 'ISDN') { $go = "/tasks/connect-isdn.cgi?s"; } 
  54.     elsif ($fld{'hardware'} eq 'T1') { $go = "/tasks/connect-t1.cgi?s"; } 
  55.     elsif ($fld{'hardware'} eq 'Ethernet or FDDI') { $go = "/tasks/connect-ether-fddi.cgi?s"; } 
  56.     #printf("Location: %s%c%c",$go,10,10); 
  57.     print "Content-type: text/html\n\n";
  58.     print "<HTML><HEAD>";
  59.     print "<META HTTP-EQUIV=\"refresh\" CONTENT=\"0; URL=$go\">";
  60.     print "</HEAD><BODY></BODY></HTML>";
  61.     exit 0;
  62. }
  63.  
  64. &generic;
  65.  
  66. sub readValues {
  67.     open(IN,"< $temp");
  68.     while(<IN>) {
  69.         @items = split(/=/);
  70.         foreach $arg (@find_vals) {
  71.             if ($arg eq $items[0]) { 
  72.                 if ($items[1] ne "\n") {
  73.                     $vals{$arg} = $items[1];
  74.                     chop $vals{$arg};
  75.                 }
  76.             }
  77.         }
  78.     }
  79.     close(IN);
  80. }
  81.  
  82. sub errorCheck {
  83.     if ($fld{'mailserver'}) {
  84.         &error("Invalid hostname: $fld{'mailserver'}.") if &check_hostname($fld{'mailserver'});
  85.     }
  86. }
  87.  
  88. sub isSecondEboard {
  89.     $ret = 0;
  90.     open(IN, "$htnet |");
  91.     while(<IN>) {
  92.         @items = split(/:/);
  93.         if ($items[0] > 0) { 
  94.             $ret = 1;
  95.             $last;
  96.         }
  97.     }
  98.     close(IN);
  99.     return $ret;
  100. }    
  101.  
  102. sub isT1Board {
  103.     $ret = 0;
  104.     open(IN, "$htnet |");
  105.     while(<IN>) {
  106.         @items = split(/\s+/);
  107.         if ($items[0] eq 'GIO') { 
  108.             $ret = 1;
  109.             $last;
  110.         }
  111.     }
  112.     close(IN);
  113.     return $ret;
  114. }
  115.  
  116. sub error {
  117.     $error = $_[0];
  118.     &generic;
  119.     exit 0;
  120. }
  121.     
  122. sub writeFile {
  123.     undef %terms;
  124.     open(IN,"< $temp");
  125.     while(<IN>) {
  126.         @items = split(/=/);
  127.         chop $items[1];
  128.         $terms{$items[0]} = $items[1];
  129.     }
  130.     close(IN);
  131.     foreach $arg (@find_vals) {
  132.         $terms{$arg} = $fld{$arg};
  133.     }
  134.     open(OUT,"> $temp");
  135.     foreach $arg (keys(%terms)) {
  136.         print OUT "$arg=$terms{$arg}\n";
  137.     }
  138.     close(OUT);
  139. }
  140.  
  141. sub generic {
  142.     print "Content-type: text/html\n\n";
  143.     print "<html><head><title>Connect to the Internet (continued)</title>\n";
  144.     print "<script language=\"JavaScript\">\n<!--\n";
  145.  
  146.     # JavaScript
  147. print "function Next()  {
  148.     form = document.page2;
  149.     if (!testMailserver(form)) return;
  150.     setTimeout('form.submit()',0); 
  151.     return;
  152. }\n";
  153. print "function Previous()  {
  154.     setTimeout('window.location=\"Tasks.connect-start.cgi?s\"',0);
  155.     return;
  156. }\n";
  157. print "function testMailserver(form) { 
  158.     Ctrl = form.mailserver;
  159.     if (Ctrl.value == \"\") return (true);
  160.     error = testHost(Ctrl.value);
  161.     if (error == 1) { errorBox (Ctrl, \"The forwarder hostname cannot contain \\npunctuation except . or - or _\"); return (false); }
  162.     if (error == 2) { errorBox (Ctrl, \"The forwarder hostname cannot begin or \\n end with a . or - or _ character.\"); return (false); }
  163.     if (error == 3) { errorBox (Ctrl, \"The forwarder hostname cannot contain \\nconsecutive . or - or _ characters.\"); return (false); }
  164.     if (error == 4) { errorBox (Ctrl, \"The forwarder hostname cannot contain spaces.\"); return (false); }
  165.     if (error == 5) { errorBox (Ctrl, \"The forwarder hostname cannot begin \\nwith a number.\"); return (false); }
  166.     return (true);
  167. }\n";
  168. print "function testHost(word) {
  169.     metaChars = \"{}()*!~<>?|[]'&^\$\@\#`\\\";:\\\\/+=,%\";
  170.     start = 0;  while (word.charAt(start) == ' ') { start++; }
  171.     end = word.length-1; while (word.charAt(end) == ' ') { end--; }
  172.     for(j = 0; j < metaChars.length; j++) {
  173.         c = metaChars.charAt(j); i = word.indexOf(c, 0); if (i != -1) return 1;
  174.     }
  175.     sch = word.charAt(start); ech = word.charAt(end);
  176.     if(sch == '.' || sch == '-' || sch == '_') return 2;
  177.     if(ech == '.' || ech == '-' || ech == '_') return 2;
  178.     for(j = start; j <= end; j++) { ch = word.charAt(j); if (ch == '.' || ch ==
  179. '-' || ch == '_') { if (word.charAt(j+1) == ch) return 3; } if (ch == ' ') { return 4; } }
  180.     if(!isNaN(parseInt(sch))) return 5;
  181.     return 0;
  182. }\n";
  183. print "function errorBox (Ctrl, ErrorMessage) {
  184.     alert (ErrorMessage);  Ctrl.focus();  return;
  185. }\n";
  186.  
  187. print "//-->\n";
  188. print "</script></head>\n\n";
  189.  
  190.     print "<body bgcolor=\'c7ded4\' background=/tasks/connect-task.bg.gif>\n";
  191.  
  192.     if ($error) {
  193.         print "<font size=4 color=ff0000><b>Error: </b>$error<br></font>";
  194.     }
  195.     print "<i>$message</i>";
  196.  
  197.     print "<table width=100%>",
  198.           "<tr><th align=left><h1>Connect to the Internet (continued)</h1></th>\n",
  199.           "<th align=right><a href=\"/newsplash.shtml\">",
  200.           "<img height=55 width=57 border=0 src=/tasks/home.gif></a>\n",
  201.           "  <a href=\"Tasks.shtml\">",
  202.           "<img height=55 width=57 border=0 src=/tasks/back.gif></a>",
  203.           "</tr></table>\n";
  204.  
  205.     printf("\n<form name=\"page2\" action=\"%s\" method=post>\n", $action);
  206.     
  207.     print "<center><table width=620>";
  208.  
  209.     @list = ('Modem','ISDN');
  210.     if ($t1board) { push(@list,"T1"); }
  211.     if ($eboard) { push(@list,"Ethernet or FDDI"); }
  212.  
  213.     print "<tr>$bo Hostname of the mail forwarder: $nb $it\n", 
  214.           &text("mailserver",$vals{'mailserver'},15), 
  215.           "$ni </tr>\n";
  216.     print "    <tr><td colspan=2>
  217.     To send mail outside your local network, your ISP might have
  218.     supplied the name of a mail forwarder host. If your ISP supplied 
  219.     the hostname of a mail forwarder, enter it in this field (not 
  220.     required unless supplied by your ISP). Your entry must be a fully
  221.     qualified hostname, such as <I>juggler.abc.com</I>.";
  222.  
  223.     print "<tr><td> </td></tr>\n";
  224.  
  225. print "<tr>$bo Type of hardware connection to your
  226. ISP: $nb $it <font size=4>\n",
  227.           &select_list("hardware",$vals{'hardware'},*list),
  228.           "</font>$ni </tr>\n";
  229.     print "    <tr><td colspan=2>
  230.     The communications hardware that links the Internet Gateway and 
  231.     an ISP is either a modem and serial line, ISDN service, a T1 line, 
  232.     or Ethernet hardware. Use the options menu above to select the type 
  233.     of hardware that connects the Internet Gateway to your ISP.
  234.     </td></tr><tr><td> </td></tr></table>\n\n";
  235.  
  236.     print '<MAP NAME="js_map1">',
  237.     '    <AREA SHAPE="rect" COORDS="0,0,59,52" HREF="javascript:Previous()"
  238.     onMouseOver="window.status=\'\';return true">',
  239.     '</MAP>';
  240.     print "\n";
  241.     print '<MAP NAME="js_map2">',
  242.     '    <AREA SHAPE="rect" COORDS="0,0,59,52" HREF="javascript:Next()"
  243.     onMouseOver="window.status=\'\';return true">',
  244.     '</MAP>';
  245.     print "\n";
  246.     print '<IMG SRC="/tasks/rightarrow.gif" BORDER=0 USEMAP="#js_map2" align="right">';
  247.     print "\n";
  248.     print '<IMG SRC="/tasks/leftarrow.gif" BORDER=0 USEMAP="#js_map1" align="right">';
  249.  
  250.     print "\n</form></body></html>";
  251. }
  252.  
  253.